home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0081_Flames.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  13KB  |  254 lines

  1.  
  2. {$G+}
  3.  
  4. program flames;
  5.  
  6. uses crt;
  7.  
  8. {**************************************************************************}
  9. {*                                                                        *}
  10. {*    FLAMES by M.D.Mackey  (C) 1993                                      *}
  11. {*        This code released into the public domain. It may be freely     *}
  12. {*        used, distributed and modified. I would appreciate it if        *}
  13. {*        credit were given, however. If you have any improvements,       *}
  14. {*        find any bugs etc. mail me at mackey@aqueous.ml.csiro.au        *}
  15. {*        with MARK: in the subject header.                               *}
  16. {*                                                                        *}
  17. {**************************************************************************}
  18.  
  19. {**************************************************************************}
  20. {*                                                                        *}
  21. {*  Modified 12-Dec-93: John M. Beck                                      *}
  22. {*                                                                        *}
  23. {*     Restructured and added wave effect by tracing sin path.            *}
  24. {*                                                                        *}
  25. {**************************************************************************}
  26.  
  27. const palette : array [1..768] of byte = (
  28.  
  29.     0,    0,    0,    0,    0,    24,    0,    0,    24,    0,    0,    28,
  30.     0,    0,   32,    0,    0,    32,    0,    0,    36,    0,    0,    40,
  31.     8,    0,   40,   16,    0,    36,   24,    0,    36,   32,    0,    32,
  32.    40,    0,   28,   48,    0,    28,   56,    0,    24,   64,    0,    20,
  33.    72,    0,   20,   80,    0,    16,   88,    0,    16,   96,    0,    12,
  34.   104,    0,    8,  112,    0,     8,  120,    0,     4,  128,    0,     0,
  35.   128,    0,    0,  132,    0,     0,  136,    0,     0,  140,    0,     0,
  36.   144,    0,    0,  144,    0,     0,  148,    0,     0,  152,    0,     0,
  37.   156,    0,    0,  160,    0,     0,  160,    0,     0,  164,    0,     0,
  38.   168,    0,    0,  172,    0,     0,  176,    0,     0,  180,    0,     0,
  39.   184,    4,    0,  188,    4,     0,  192,    8,     0,  196,    8,     0,
  40.   200,   12,    0,  204,   12,     0,  208,   16,     0,  212,   16,     0,
  41.   216,   20,    0,  220,   20,     0,  224,   24,     0,  228,   24,     0,
  42.   232,   28,    0,  236,   28,     0,  240,   32,     0,  244,   32,     0,
  43.   252,   36,    0,  252,   36,     0,  252,   40,     0,  252,   40,     0,
  44.   252,   44,    0,  252,   44,     0,  252,   48,     0,  252,   48,     0,
  45.   252,   52,    0,  252,   52,     0,  252,   56,     0,  252,   56,     0,
  46.   252,   60,    0,  252,   60,     0,  252,   64,     0,  252,   64,     0,
  47.   252,   68,    0,  252,   68,     0,  252,   72,     0,  252,   72,     0,
  48.   252,   76,    0,  252,   76,     0,  252,   80,     0,  252,   80,     0,
  49.   252,   84,    0,  252,   84,     0,  252,   88,     0,  252,   88,     0,
  50.   252,   92,    0,  252,   96,     0,  252,   96,     0,  252,  100,     0,
  51.   252,  100,    0,  252,  104,     0,  252,  104,     0,  252,  108,     0,
  52.   252,  108,    0,  252,  112,     0,  252,  112,     0,  252,  116,     0,
  53.   252,  116,    0,  252,  120,     0,  252,  120,     0,  252,  124,     0,
  54.   252,  124,    0,  252,  128,     0,  252,  128,     0,  252,  132,     0,
  55.   252,  132,    0,  252,  136,     0,  252,  136,     0,  252,  140,     0,
  56.   252,  140,    0,  252,  144,     0,  252,  144,     0,  252,  148,     0,
  57.   252,  152,    0,  252,  152,     0,  252,  156,     0,  252,  156,     0,
  58.   252,  160,    0,  252,  160,     0,  252,  164,     0,  252,  164,     0,
  59.   252,  168,    0,  252,  168,     0,  252,  172,     0,  252,  172,     0,
  60.   252,  176,    0,  252,  176,     0,  252,  180,     0,  252,  180,     0,
  61.   252,  184,    0,  252,  184,     0,  252,  188,     0,  252,  188,     0,
  62.   252,  192,    0,  252,  192,     0,  252,  196,     0,  252,  196,     0,
  63.   252,  200,    0,  252,  200,     0,  252,  204,     0,  252,  208,     0,
  64.   252,  208,    0,  252,  208,     0,  252,  208,     0,  252,  208,     0,
  65.   252,  212,    0,  252,  212,     0,  252,  212,     0,  252,  212,     0,
  66.   252,  216,    0,  252,  216,     0,  252,  216,     0,  252,  216,     0,
  67.   252,  216,    0,  252,  220,     0,  252,  220,     0,  252,  220,     0,
  68.   252,  220,    0,  252,  224,     0,  252,  224,     0,  252,  224,     0,
  69.   252,  224,    0,  252,  228,     0,  252,  228,     0,  252,  228,     0,
  70.   252,  228,    0,  252,  228,     0,  252,  232,     0,  252,  232,     0,
  71.   252,  232,    0,  252,  232,     0,  252,  236,     0,  252,  236,     0,
  72.   252,  236,    0,  252,  236,     0,  252,  240,     0,  252,  240,     0,
  73.   252,  244,    0,  252,  244,     0,  252,  244,     0,  252,  248,     0,
  74.   252,  248,    0,  252,  248,     0,  252,  248,     0,  252,  252,     0,
  75.   252,  252,    4,  252,  252,     8,  252,  252,    12,  252,  252,    16,
  76.   252,  252,   20,  252,  252,    24,  252,  252,    28,  252,  252,    32,
  77.   252,  252,   36,  252,  252,    40,  252,  252,    40,  252,  252,    44,
  78.   252,  252,   48,  252,  252,    52,  252,  252,    56,  252,  252,    60,
  79.   252,  252,   64,  252,  252,    68,  252,  252,    72,  252,  252,    76,
  80.   252,  252,   80,  252,  252,    84,  252,  252,    84,  252,  252,    88,
  81.   252,  252,   92,  252,  252,    96,  252,  252,   100,  252,  252,   104,
  82.   252,  252,  108,  252,  252,   112,  252,  252,   116,  252,  252,   120,
  83.   252,  252,  124,  252,  252,   124,  252,  252,   128,  252,  252,   132,
  84.   252,  252,  136,  252,  252,   140,  252,  252,   144,  252,  252,   148,
  85.   252,  252,  152,  252,  252,   156,  252,  252,   160,  252,  252,   164,
  86.   252,  252,  168,  252,  252,   168,  252,  252,   172,  252,  252,   176,
  87.   252,  252,  180,  252,  252,   184,  252,  252,   188,  252,  252,   192,
  88.   252,  252,  196,  252,  252,   200,  252,  252,   204,  252,  252,   208,
  89.   252,  252,  208,  252,  252,   212,  252,  252,   216,  252,  252,   220,
  90.   252,  252,  224,  252,  252,   228,  252,  252,   232,  252,  252,   236,
  91.   252,  252,  240,  252,  252,   244,  252,  252,   248,  252,  252,   252,
  92.   252,  252,  240,  252,  252,   244,  252,  252,   248,  252,  252,   252);
  93.  
  94.    radius    = 1.9;
  95.    frequency = 2;
  96.    angleinc  = 3 * pi / frequency;
  97.  
  98. var
  99.    count       : word;
  100.    delta       : integer;
  101.    path        : array[0..199] of word;
  102.    buffer      : array[0..102,0..159] of integer;
  103.  
  104. procedure buildpath;
  105.    var
  106.       count     : byte;
  107.       currangle : real;
  108.    begin
  109.       currangle := pi;
  110.       for count := 0 to 199 do
  111.          begin
  112.             path[count] := 320 + round(radius*sin(currangle));
  113.  
  114.             { the sin path _must_ lie on an even number }
  115.             { otherwise the picture will be garbage     }
  116.  
  117.             if path[count] mod 2 <> 0 then
  118.                if path[count] > 320 then
  119.                   dec(path[count])            { round down }
  120.                else
  121.                   inc(path[count]);           { round up   }
  122.  
  123.             { the path is rounded to the closest even number to 320 }
  124.  
  125.             currangle := currangle + angleinc;
  126.          end;
  127.    end;
  128.  
  129. begin
  130.   randomize;
  131.   buildpath;
  132.  
  133.   asm
  134.      mov   ax,13h              { ; AX := 13h                            }
  135.      int   10h                 { ; Set Mode 13h (320x200x256)           }
  136.  
  137.      xor   ax,ax               { ; AX := 0                              }
  138.      mov   cx,768              { ; CX := # of palette entries           }
  139.      mov   dx,03C8h            { ; DX := VGA Port                       }
  140.      mov   si,offset palette   { ; SI := palette[0]                     }
  141.  
  142.      out   dx,al               { ; send zero to index port              }
  143.      inc   dx                  { ; inc to write port                    }
  144.  
  145.    @l1:
  146.  
  147.      mov   bl,[si]             { ; set palette entry                    }
  148.      shr   bl,2                { ; divide by 4                          }
  149.      mov   [si],bl             { ; save entry                           }
  150.      outsb                     { ; and write to port                    }
  151.      dec   cx                  { ; CX := CX - 1                         }
  152.      jnz   @l1                 { ; if not done then loop                }
  153.  
  154.      mov   ax,seg buffer       { ; AX := segment of buffer              }
  155.      mov   es,ax               { ; ES := AX                             }
  156.      mov   di,offset buffer    { ; DI := buffer[0]                      }
  157.      mov   cx,8109             { ; CX := sizeof(buffer) div 2           }
  158.      xor   ax,ax               { ; AX := 0                              }
  159.      rep   stosw               { ; clear every element in buffer to zero}
  160.   end;
  161.  
  162.   repeat
  163.  
  164.      asm
  165.         mov   bx,1             { ; BX := 1                              }
  166.         mov   si,offset path   { ; SI := path[0]                        }
  167.  
  168.         mov   cx,16160         { ; CX := # of elements to change        }
  169.         mov   di,offset buffer { ; DI := buffer[0]                      }
  170.         add   di,320           { ; DI := buffer[320] (0,1)              }
  171.  
  172.      @l2:
  173.  
  174.         mov   ax,ds:[di-2]     { ; AX := buffer[DI-2]    (x-1,y)        }
  175.         add   ax,ds:[di]       { ; AX += buffer[DI]      (x  ,y)        }
  176.         add   ax,ds:[di+2]     { ; AX += buffer[DI+2]    (x+1,y)        }
  177.         add   ax,ds:[di+320]   { ; AX += buffer[DI+320]  (x,y+1)        }
  178.         shr   ax,2             { ; AX := AX div 4 (calc average)        }
  179.  
  180.         jz    @l3              { ; if AX = 0 then skip next line        }
  181.         dec   ax               { ; else AX--                            }
  182.  
  183.      @l3:
  184.  
  185.         push  di               { ; save DI                              }
  186.         sub   di,ds:[si]       { ; DI := (x + or - sin,y-1)             }
  187.         mov   word ptr ds:[di],ax { store AX somewhere one line up      }
  188.         pop   di               { ; restore DI                           }
  189.  
  190.         inc   di               { ; DI++                                 }
  191.         inc   di               { ; DI++ (move to next word)             }
  192.  
  193.         inc   bx               { ; BX++                                 }
  194.         cmp   bx,320           { ; if bx <> 320                         }
  195.         jle   @l4              { ; then jump to @l4                     }
  196.         mov   bx,1             { ; else BX := 1 (we're on a new line)   }
  197.         inc   si               { ; point SI to next element in path     }
  198.         inc   si               { ;                                      }
  199.  
  200.      @l4:
  201.         dec   cx               { ; CX--                                 }
  202.         jnz   @l2              { ; if CX <> 0 then loop                 }
  203.      end;
  204.  
  205.      for count := 0 to 159 do {set new bottom line}
  206.         begin
  207.            if random < 0.4 then
  208.               delta := random(2)*255;
  209.            buffer[101,count] := delta;
  210.            buffer[102,count] := delta;
  211.         end;
  212.  
  213.      asm
  214.         mov   si,offset buffer { ; SI := buffer[0]                      }
  215.         mov   ax,0A000h        { ; AX := 0A000h (vga segment)           }
  216.         mov   es,ax            { ; ES := AX                             }
  217.         xor   di,di            { ; DI := 0                              }
  218.         mov   dx,100           { ; DX := 100 (# of rows div 2)          }
  219.  
  220.      @l5:
  221.         mov   bx,2             { ; BX := 2                              }
  222.  
  223.      @l6:
  224.         mov   cx,160           { ; CX := 160 (# of cols div 2)          }
  225.  
  226.      @l7:
  227.         mov   al,ds:[si]       { ; AL := buffer[si]                     }
  228.         mov   ah,al            { ; AH := AL (replicate byte)            }
  229.         mov   es:[di],ax       { ; store two bytes into video memory    }
  230.         inc   di               { ; move to next word in VRAM            }
  231.         inc   di               { ;                                      }
  232.         inc   si               { ; move to next word in buffer          }
  233.         inc   si               { ;                                      }
  234.         dec   cx               { ; CX--                                 }
  235.         jnz   @l7              { ; repeat until done with column        }
  236.  
  237.         sub   si,320           { ; go back to start of line in buffer   }
  238.         dec   bx               { ; BX--                                 }
  239.         jnz   @l6              { ; repeat until two columns filled      }
  240.  
  241.         add   si,320           { ; restore position in buffer           }
  242.         dec   dx               { ; DX--                                 }
  243.         jnz   @l5              { ; repeat until 100 rows filled         }
  244.      end;
  245.  
  246.   until keypressed;
  247.  
  248.   asm
  249.      mov   ax,03h              { ; AX := 3h                             }
  250.      int   10h                 { ; restore text mode                    }
  251.   end;
  252.  
  253. end.
  254.